<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- <p>{{ sex === 1 ? "男" : "女" }}</p> -->
      <p :title="timer | formatTime">{{ sex | fn | fn2 }}</p>
      <p>{{ timer | formatTime }}</p>
    </div>

    <script src="../Vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          sex: 2,
          timer: 1652924303276,
        },
        // 过滤器的作用是用来做文本格式化的
        // 过滤器可以给双大括号用，也可以给v-bind表达式用
        // 过滤器可以串联的

        // 放过滤器函数
        filters: {
          // 可以接受竖线前面的值作为参数
          fn(val) {
            return val === 1 ? "男" : "女";
          },
          fn2(val) {
            return val === "男" ? "♂" : "♀";
          },
          formatTime(val) {
            const now = new Date(val);
            var year = now.getFullYear();
            var month = now.getMonth() + 1;
            var date = now.getDate();
            var hour = now.getHours();
            var minute = now.getMinutes();
            var second = now.getSeconds();
            return (
              year +
              "-" +
              month +
              "-" +
              date +
              " " +
              hour +
              ":" +
              minute +
              ":" +
              second
            );
          },
        },
      });
    </script>
  </body>
</html>
